$(document).ready(function () {

    let expression = "";

    /*点击输入值*/
    $(".but_val").click(function () {
        let type = $(this).val();
        if (expression.trim() === "ERROR".trim()) {
            expression = type;
        } else {
            expression = expression + type;
        }
        $(".screen").val(expression);
    })

    /*点击清空*/
    $(".but_ac").click(function () {
        expression = "";
        $(".screen").val(expression);
    })

    /*点击等号提交*/
    $(".but_submit").click(function () {
        if (expression == null || expression === '' || expression === 'ERROR' ||
            !expression.includes('+') && !expression.includes('-') && !expression.includes('×') && !expression.includes('÷')) {
            $(".screen").val(expression);
        } else {
            expression = $(".screen").val();
            $.post("/calculator", {
                "expression": expression
            }, function (result) {
                expression = result;
                $(".screen").val(expression);
            });
        }
    })
});